#include<sys/wait.h>
#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>

int main()
{
  pid_t id = fork();
  int cnt = 5;
  if(id == 0)
  {
    //子进程
    while(cnt)
    {
      printf(" I am child process,id :%d, 父进程：%d,cnt: %d\n",getpid(),getppid(),cnt--);
      sleep(1);
    } 
    exit(520);
  }

  //父进程
  int status = 0;
  pid_t ret = waitpid(id,&status,0);
  if(id > 0)
  {
    printf("wait success: %d,sig number: %d,child exit code: %d\n",ret,(status & 0x7F),(status >> 8)&0xFF);
  }
  sleep(5);
  return 0;
}
